#pragma once

#include"HashTable.h"

namespace bit
{
	//template<class K, class Hash = HashFunc<K>>
	template<class K>
	class unordered_set
	{
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		
		typedef typename hash_bucket::HashTable<K, K, SetKeyOfT>::Iterator iterator; //取类模板里的内置类型，需要加一个typenam

		iterator begin()
		{
			return _ht.Begin();
		}

		iterator end()
		{
			return _ht.End();
		}

		bool insert(const K& key)
		{
			return _ht.Insert(key);
		}

	private:
		hash_bucket::HashTable<K, K, SetKeyOfT> _ht;
	};


	void test_set()
	{
		unordered_set<int> s;
        int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
		//int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14, 3,3,15 }; 
		for (auto e : a)
		{
			s.insert(e);
		}

		for (auto e : s)
		{
			cout << e << " ";
		}
		cout << endl;

		unordered_set<int>::iterator it = s.begin();
		while (it != s.end())
		{
			//*it += 1;
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}
}
